<div class="container">
    <div class="crumbs">
        <ul id="breadcrumbs" class="breadcrumb">
            <li><i class="icon-home"></i> <a href="">Users</a></li>
        </ul>

    </div>
    <div class="page-header">
        <div class="page-title"><h3>Users</h3></div>

    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="widget box">
                <div class="widget-header"><h4><i class="icon-reorder"></i>Admin</h4>

                    <div class="toolbar no-padding">
                        <div class="btn-group"><span class="btn btn-xs widget-collapse"><i
                                    class="icon-angle-down"></i></span></div>
                    </div>
                </div>
                <div class="widget-content">
                    <table class="table table-striped table-bordered table-hover datatable">
                        <thead>
                        <tr>
                            <th class="align-center">ID</th>
                            <th class="align-center">Name</th>
                            <th class="align-center">Email</th>
                            <th class="align-center">Tel</th>
                            <th class="align-center"></th>
                        </tr>
                        </thead>
                        <tbody id="lstAdmin">
                        <?php
                        foreach ($admins as $admin) {
                            ?>
                            <tr>
                                <td class="align-center"><?php echo $admin->id; ?></td>
                                <td class="align-center"><?php echo $admin->name; ?></td>
                                <td class="align-center"><?php echo $admin->email; ?></td>
                                <td class="align-center"><?php echo $admin->tel; ?></td>
                                <td>
                                    <a href="javascript:void(0);"><span
                                            class="label label-danger removeadmin">Remove admin</span></a>
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="widget box">
                <div class="widget-header"><h4><i class="icon-reorder"></i>Users</h4>

                    <div class="toolbar no-padding">
                        <div class="btn-group"><span class="btn btn-xs widget-collapse"><i
                                    class="icon-angle-down"></i></span></div>
                    </div>
                </div>
                <div class="widget-content">
                    <table class="table table-striped table-bordered table-hover datatable">
                        <thead>
                        <tr>
                            <th class="align-center">ID</th>
                            <th class="align-center">Name</th>
                            <th class="align-center">Email</th>
                            <th class="align-center">Tel</th>
                            <th class="align-center"></th>
                        </tr>
                        </thead>
                        <tbody id="lstUser">
                        <?php
                        foreach ($users as $user) {
                            ?>
                            <tr>
                                <td class="align-center"><?php echo $user->id; ?></td>
                                <td class="align-center"><?php echo $user->name; ?></td>
                                <td class="align-center"><?php echo $user->email; ?></td>
                                <td class="align-center"><?php echo $user->tel; ?></td>
                                <td>
                                    <a href="javascript:void(0);"><span class="label label-info makeadmin">Make admin</span></a>
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="widget box">
                <div class="widget-header"><h4><i class="icon-reorder"></i>Authors</h4>

                    <div class="toolbar no-padding">
                        <div class="btn-group"><span class="btn btn-xs widget-collapse"><i
                                    class="icon-angle-down"></i></span></div>
                    </div>
                </div>
                <div class="widget-content">
                    <table class="table table-striped table-bordered table-hover datatable">
                        <thead>
                        <tr>
                            <th class="align-center">ID</th>
                            <th class="align-center">Name</th>
                            <th class="align-center">Email</th>
                            <th class="align-center">Tel</th>
                            <th class="align-center"></th>
                        </tr>
                        </thead>
                        <tbody id="lstAuthor">
                        <?php
                        foreach ($authors as $author) {
                            ?>
                            <tr>
                                <td class="align-center"><?php echo $author->id; ?></td>
                                <td class="align-center"><?php echo $author->name; ?></td>
                                <td class="align-center"><?php echo $author->email; ?></td>
                                <td class="align-center"><?php echo $author->tel; ?></td>
                                <td>
                                    <a href="javascript:void(0);"><span class="label label-info makeadmin">Make admin</span></a>
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.makeadmin').click(function(){
        var self = this;
        $.post('user/make_admin',{
            id : $(self).closest('tr').find('td').eq(0).text()
        },function(data){
            if (parseInt(data) == 1)
            {
                location.reload();
            }
        })
    });
    $('.removeadmin').click(function(){
        var self = this;
        $.post('user/remove_admin',{
            id : $(self).closest('tr').find('td').eq(0).text()
        },function(data){
            if (parseInt(data) == 1)
            {
                location.reload();
            }
        })
    });

</script>